//
//  FSCExaminationListViewModel.swift
//  FamiliesSchoolConnection
//
//  Created by 花花蔡 on 2016/12/29.
//  Copyright © 2016年 com.HuaHuaCai. All rights reserved.
//

import UIKit
import SVProgressHUD

class FSCExaminationListViewModel {

    var examinationModelArr:[FSCExaminationModel] = []
    
    
    func loadData( finished:@escaping (_ isOk:Bool)->()  ) -> Void {
        
        let urlStr = "ZH-schoolname-S-getExamScore"
        let parm = ["key":userID,"id":1] as [String : Any]
        
        FSCNetworkTools.shared.request(url: urlStr, parameters: parm) { [weak self](data, error) in
            
            guard let data = data as? NSDictionary else {
                SVProgressHUD.showInfo(withStatus: "网络差")
                return
            }
            
            print(data)
            switch data["result"] as! Int {
            case 0:
                guard let dictArr = data["data"] as? [[String:Any]] else {
                    return
                }
                
                for dic in dictArr {
                    let model = FSCExaminationModel(dict:dic)
                    self?.examinationModelArr.append(model)
                }
                finished(true)
            case 1:
                SVProgressHUD.showInfo(withStatus: "无数据")
                finished(false)
            default:
                break
            }
        }
    }
}
